<template>
  <div>
    <el-form ref="form" :model="type" label-width="80px">
      <el-form-item label="分类名称">
        <el-input ref="typeName" v-model="type.typeName" v-focus />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确认</el-button>
        <el-button @click="closeForm">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import TypeApi from '@/api/type'
export default {
  data() {
    return {
      type: {}
    }
  },
  created() {
    // this.$nextTick(() => {
    //   this.$refs.typeName.focus()
    // })
  },
  methods: {
    onSubmit() {
      TypeApi.save(this.type).then(resp => {
        this.$message.success(resp.msg)
        this.$emit('getTypeList')
        this.$emit('closeAddTypeForm')
      })
    },
    closeForm() {
      this.$emit('closeAddTypeForm')
    },
    init() {
      this.$nextTick(() => {
        this.$refs.typeName.focus()
      })
    }
  }
}
</script>
